package com.cjs.example.config;

import org.jetbrains.annotations.Nullable;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

/**
 * @Author: lijunwei
 * @Time: 2019/6/17 15:40
 *
 * 获取路由key
 * https://www.cnblogs.com/softidea/p/7127874.html?utm_source=itdadao&utm_medium=referral
 * AbstractRoutingDataSource实现动态数据源切换
 *
 * 在Spring 2.0.1中引入了AbstractRoutingDataSource, 该类充当了DataSource的路由中介,
 * 能有在运行时, 根据某种key值来动态切换到真正的DataSource上。
 */
public class MyRoutingDataSource extends AbstractRoutingDataSource {
    @Nullable
    @Override
    protected Object determineCurrentLookupKey() {
        return DBContextHolder.get();
    }
}
